<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\configs\admin;

use app\admin\controller\Admin;
use think\Db;
use app\common\builder\ZBuilder;

/**
 * User控制器
 * @package app\banner\admin
 */
class User extends Admin
{
    /**
     * 首页
     * @author 蔡伟明 <314013107@qq.com>
     * @return mixed
     */

    public function index(){
        $map = $this->getMap();
        $data_list = Db::name('user')
            ->alias("a")
            ->join("user b","a.recommend_id=b.id","left")
            ->join("user c","a.re_id=c.id","left")
            ->where($map)
            ->field("a.*,b.username recommend_name,c.username re_name")
            ->order("a.id desc")
            ->paginate();
           
        // 使用ZBuilder快速创建数据表格
        return ZBuilder::make('table')
            ->setPageTitle('会员中心') // 设置页面标题
            ->setTableName('user') // 设置数据表名
            ->hideCheckbox()
            ->setSearch(['a.username' => '姓名','a.nickname' => '昵称','b.username'=>'推荐人','c.username'=>'责任人']) // 设置搜索参数
            ->addColumns([ // 批量添加列
                ['username','姓名'],
                ['nickname','微信昵称'],
                ['avatar','头像',"img_url"],
                ['driving_license','行驶证照片',"img_url"],
                ['idcard','身份证',"text.edit"],
                ['mobile','手机号',"text.edit"],
                ['createtime','注册时间','datetime'],
                ['status','黑名单(允许登陆)','switch'],
                ['recommend_name','推荐人'],
                ['re_name','责任人'],
                ['openid','openid'],
                ['right_button', '操作', 'btn']
            ])
           // ->addRightButtons('delete') // 批量添加右侧按钮
          //  ->addTopButton('btn_excel_view',$btn_excel_view) 
            ->setRowList($data_list) // 设置表格数据
            ->fetch(); // 渲染页面
    }
    
    public function excel_out_sign(){
        $list=session("user_data_list");
        $list=$list->toArray();
        $data=$list['data'];
        if(empty($data)){
            $this->error("没有简历数据");
        }
        
        $ids=array_column($data,"id");
        

        // 数据列表
        $data_list  = Db::name('zp_resume')
        ->alias("a")
        ->join("user b","a.user_id=b.id")
        ->field("a.*,b.username,if(a.sex=1,'男','女') as sex")
        ->where("b.id","in",$ids)
        ->order("a.id desc")
        ->select();
        //exit;
        // 设置表头信息（对应字段名,宽度，显示表头名称）
        $cellName = [
            ['user_name', '30','姓名'],
            ['sex', '12','性别'],
            ['birthday', '25','生日'],
            ['phone', '16','电话'],
            ['minzu', '8','民族'],
            ['qiw_dd', '20','期望地点'],
            ['qiw_xz', '10','期望薪资'],
            ['qiw_zw', '15','期望职位'],
            ['card', '15','银行卡'],
            ['bank', '15','开户行'],
            ['web', '15','开户网点'],
        ];
        
        
        plugin_action('Excel/Excel/export', ['简历数据'.date('Y-m-d H:i:s'), $cellName, $data_list]);
    }
    
    
    
    
    public function message($id){
        if ($this->request->isPost()) {
            $data = $this->request->post();
            
            $r=db('user_message')->insert([
                "content"=>$data['content'],
                "user_id"=>$id,
                "create_time"=>date("Y-m-d H:i:s"),
            ]);
            if($r){
                return $this->success('发送成功', null, '_close_pop');
            }else {
                return $this->error('发送失败', null, '_close_pop');
            }
        }
        // 使用ZBuilder快速创建表单
        return ZBuilder::make('form')
        ->setPageTitle('发送消息给用户') // 设置页面标题
        ->addFormItems([ // 批量添加表单项
            ['textarea', 'content', '消息内容'],
            
        ])
        ->fetch();
    }
    
    
}















